﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace Jermaine.Serialization
{

    /// <summary>
    /// Factory to get Serializer
    /// </summary>
    public class SerializerFactory
    {

        private static readonly Dictionary<string, ISerializer> Cache = new Dictionary<string, ISerializer>();


        public static T GetSerializer<T>() where T : ISerializer {
            var type = typeof(T);
            var name = type.FullName;
            if (Cache.ContainsKey(name)) {
                return (T)Cache[name];
            }
            var o = Activator.CreateInstance<T>();
            Cache[name] = o as ISerializer;
            return o;

        }

    }
}
